<?php
/*
 * 手机客户端店铺-商品介绍接口
 * 2014-02-26
 * 2014-05-08 (已查) 
 */
include "inc/public_header.php";

include "func/user.php";				//用户信息处理函数


$reJson = array(); //构建返回值

/*
 * 常量
 */

//小图URL根路径
$S_IMG_BASE_URL = "http://www.chinalaohu.com/modules/miniature.php?w=640&p=/uploads/shop/productImg/";
//大图URL根路径
$IMG_BASE_URL = "http://www.chinalaohu.com/modules/miniature.php?w=1000&p=/uploads/shop/productImg/";

$product_id 			= $_REQUEST["goodsId"];	//商品id

//获取用户信息
$uInfoArr = user_getInfoFromUUID();
$uid = $uInfoArr["uid"];//用户信息主键

$reJson["success"] = "1";
$list = array();
$canBook = "0";
$reason = "商品已下架";
$bookPropMsg = "";
$business_type = 0;
if ($uid){
$sql = "SELECT business_type FROM user_base where uid='".$uid."'";
$db->query($sql);
if ($db->next_record()){
	$business_type = $db->f("business_type");
}
}
$sql ="select sc_id from shop_product_sc where product_id='".$product_id."' and uid='".$uid."'";
$db->query($sql);
if($db->next_record()){
	$hasCollect = "1";
}else{
	$hasCollect = "0";
}

//商品介绍信息
$sql = "SELECT a.image,a.product_name,a.price,a.qyprice,a.aprice,a.color,a.size,a.material,a.material_other,a.shop_id,a.quantity,a.salesvolume,
			 b.shop_name,c.region,(select count(*) from shop_product_assess where product_id=a.product_id) as count
			 from shop_product a
						INNER JOIN
						(select shop_id,shop_name,city from shop_info) b on a.shop_id=b.shop_id
						INNER JOIN
						region c on b.city=c.codes
			 where a.product_id='".$product_id."'"; 
$db->query($sql);
$productArr = array();
if($db->next_record()){
	$image	   		= $db->f("image");
	$image			= $image."&a=1";
	$product_name 	= $db->f("product_name");
	$price	  		= $db->f("price");
	$qyprice	  	= $db->f("qyprice");
	$aprice	  		= $db->f("aprice");
	if ($aprice!=0){
	$bookingPrice	= "预付款:￥".$aprice;
	}else{
	$bookingPrice	= "";
	}
	$color	   		= $db->f("color");
	$size	   		= $db->f("size");
	if ($db->f("material") == "其他"){
	$material	   	= $db->f("material_other");
	}else{
	$material		= $db->f("material");
	}
	$shop_id	   	= $db->f("shop_id");
	$quantity	   	= $db->f("quantity");
	$salesvolume	= $db->f("salesvolume");
	if ($db->f("quantity") == $db->f("salesvolume")){
	$canBuy = "0";
	}else{
	$canBuy = "1";
	}
	$kuncun = $db->f("quantity")-$db->f("salesvolume");
	$propMsg = "";
	$shop_name	   	= $db->f("shop_name");
	$region	   		= $db->f("region");
	$count	   		= $db->f("count");
	$description	= "库存：".$kuncun."\n";
	$description	= $description."颜色：".$color."\n";
	$description	= $description."尺寸：".$size."\n";
	$description	= $description."材质：".$material."\n";
	$description	= $description."评价：已有".$count."人评价";
	
}
//echo $shop_id;
//echo $uid;
//echo $product_id;
if ($uid){
$sql="select c.shop_id from shop_order_detail a inner join shop_order b on a.pid=b.id INNER JOIN shop_product c on a.product_id=c.product_id where b.uid='".$uid."' and b.del_type='0' and c.shop_id in ('81','86')";
$dc=$db1->query($sql);
if($db1->next_record()){
$shop_id1 = $db1->f('shop_id');
}
$sql="select c.product_id from shop_order_detail a inner join shop_order b on a.pid=b.id INNER JOIN shop_product c on a.product_id=c.product_id where b.uid='".$uid."' and b.del_type='0' and c.product_id='".$product_id."' and c.shop_id in ('87','88','92','93')";
$dc=$db1->query($sql);
if($db1->next_record()){
$product_id1 = $db1->f('product_id');
}
}

$bookListArr = array();

			
//放入商品介绍信息
$list[] = array(
		"bigImgUrl"=>$IMG_BASE_URL.$image
		,"imgUrl"=>$S_IMG_BASE_URL.$image
	);
$reJson["list"] = $list;			//图片地址
$reJson["propMsg"] = $propMsg;				
$reJson["name"] = $product_name;				//商品名称
$reJson["hasCollect"] = $hasCollect;
if ($business_type==1 and $qyprice and $qyprice<$price){
$reJson["origPrice"] = $price;						//商品价格
$reJson["currPrice"] = $qyprice;						//商品价格
}else{
$reJson["currPrice"] = $price;						//商品价格
}
$reJson["bookingPrice"] = $bookingPrice;
$reJson["bookPropMsg"] = $bookPropMsg;	
$reJson["canBuy"] = $canBuy;
$reJson["canBook"] = $canBook;
$reJson["reason"] = $reason;
$reJson["bookList"] = $bookListArr;
$reJson["description"] = $description;			//商品的具体情况描述
$reJson["shopName"] = $shop_name;				//店铺名称
$reJson["location"] = $region;					//所在地
$reJson["shopId"] = $shop_id;					//店铺id



echo json_encode($reJson);
?>
